package com.example.love_margin.Mapper;


import com.example.love_margin.Entity.Adopt;
import com.example.love_margin.Mapper.configuer.DeleteMany;
import com.example.love_margin.Mapper.configuer.SeletPetPicture;
import com.example.love_margin.Mapper.configuer.UpSql;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdoptMapper {


    @Insert("INSERT INTO adopt(pet_id,user_id,adopt_time,adopt_state,adopt_day,observation_day,adopt_process,special_note)" +
            "values(#{pet_id},#{user_id},#{adopt_time},#{adopt_state},#{adopt_day},#{observation_day},#{adopt_process},#{special_note})")
    int addAdopt(Adopt adopt);

    //删除单条
    @Delete("DELETE FROM adopt WHERE adopt_id=#{adopt_id}")
    int deleteAdopt(@Param("adopt_id") int adopt_id);

    //批量删除

    @DeleteProvider(type = DeleteMany.class,method = "deleteM")
    int deleteScienceM(String sql);


    //查询多个对象的宠物的id用以删除
    @SelectProvider(type = SeletPetPicture.class,method = "SelectPetP")
    List<Integer> selectPetAll(String URL);


    //通过id进行修改宠物信息
    @Update("UPDATE adopt SET pet_id=#{pet_id},user_id=#{user_id},adopt_time=#{adopt_time}," +
            "adopt_state=#{adopt_state},adopt_day=#{adopt_day},observation_day=#{observation_day}," +
            "adopt_process=#{adopt_process},special_note=#{special_note} " +
            "WHERE adopt_id = #{adopt_id}")
    int upSale(Adopt adopt);

    //单条通过
    @Update("UPDATE adopt SET adopt_state=#{adopt_state} WHERE adopt_id = #{adopt_id}")
    int upOneStat(@Param("adopt_id") int adopt_id);

    //批量通过申请
    @UpdateProvider(type = UpSql.class,method = "returnSQL")
    int upStateMany(String sql);

    //查询我的领养宠物列表，根据已通过或者为通过
    @Select("SELECT pet_id FROM adopt WHERE user_id = #{user_id} AND adopt_state = #{adopt_state}")
    Integer[] selectOneAdoptAll(@Param("user_id") int user_id,@Param("adopt_state") String adopt_state);


//    //查询我的领养宠物列表，根据已通过或者为通过
//    @Select("SELECT * FROM adopt WHERE user_id = #{user_id} AND adopt_state = #{adopt_state}")
//    List<Adopt> selectOneAdoptAll(@Param("user_id") int user_id,@Param("adopt_state") String adopt_state);
//

    //id查询单个领养申请信息
    @Select("SELECT * FROM adopt WHERE adopt_id = #{adopt_id}")
    Adopt selectAdoptO(@Param("adopt_id") int adopt_id);

    //id查询单个领养申请信息
    @Select("select count(*) from  adopt where user_id = #{user_id}")
    int selectAdoptPets(@Param("user_id") int user_id);

    //后台查询领养宠物列表
    @Select("SELECT * FROM adopt")
    List<Adopt> selectAdoptM();

}
